<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 配送网点设置操作功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * @author   create by allen.qiang
 */

class pa_distributionSetting {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch ( $_REQUEST['operFlg'] ) {

                case 1://配送站列表
                    $this->distributionList();
                    break;

                case 2: //编辑配送站
                    $this->distributionSave();
                    break;

                default:
                    backendError();
                    break;

            }

        } else {

            backendError();

        }

    }

    /**
     *配送站列表页
     */
    private function distributionList () {

        global $G_PGLOB;


        $G_PGLOB->smarty->assign('edit_permission', $G_PGLOB->has_permission(25));
        $G_PGLOB->smarty->display('system/distributionList.tpl');

    }

    /*
    *
    * 编辑配送站
    */
    private function distributionSave(){

        global $G_PGLOB;

        quanli_include('module/base/system/sysDistribution.class.php');

        quanli_include('module/base/system/mapAreaZoning.class.php');

        //实例地图区域划分 公共方法类
        $mapAreaZoning = new mapAreaZoning();

        $arg_array = array(
            'type' => 1
        );

        $distribution_array = $mapAreaZoning->searchMapArea( $arg_array );
        if (!$distribution_array) {
            backendError('地图区域划分信息没有找到，请先添加地图区域划分');
        }

        $G_PGLOB->smarty->assign_by_ref('distribution_array', $distribution_array);

        //实例配送站类
        $sysDistribution = new sysDistribution($G_PGLOB->DBCA);

        $operFlg = 2;                                           //添加配送站

        //修改配送站
        if ( isset($_REQUEST['distribution_id']) ) {

            $operFlg = 3;

            $arg_array = array(
                'distribution_id'=>$_REQUEST['distribution_id']
            );
            //查找配送站
            $item_array = $sysDistribution->search( $arg_array ) ;

            if ( $item_array ) {
                $G_PGLOB->smarty->assign('templateMsg',$item_array[0]);
            } else {
                $G_PGLOB->smarty->assign('templateMsg',NULL);
            }

            //查询地图区域ID
            $search_sql = "SELECT areaID FROM sys_distribution_map_area WHERE distribution_id = ? ";
            $area_array = $G_PGLOB->DBCA->stmt_query($search_sql, 'i', $_REQUEST['distribution_id']);

            if($area_array){
                foreach($area_array as $item){
                    $area_id_data[] = $item->areaID;
                }
                $G_PGLOB->smarty->assign('area_id_json', json_encode($area_id_data));
            }

        }

        $G_PGLOB->smarty->assign('operFlg',$operFlg);
        $G_PGLOB->smarty->display('system/distributionAdd.tpl');
    }

}